using System.Collections;
using UnityEngine;

public class Enemy0 : TypeOfEnemy
{
	public void Init(int arrayNum)
	{
		arrayNumForAllObjectsInfo = arrayNum;
		SetEnemy();
		StopAllCoroutines();
		StartCoroutine(Motions());
		StartCoroutine(RefreshPosition());
		StartCoroutine(IE_Update());
		StartCoroutine(IE_DrawShadow());
		grabingWeaponID = 0;
		EquipGetOrDrop("Enemy", true, 0, grabingWeaponID);
		if (Random.Range(0, 10) == 0 && LevelController.instance.level > 2)
		{
			SR_InHands[0].sprite = Sprites.instance.singleSpriteList[0];
			SR_InHands[0].color = new Color(0f, 0f, 0f);
		}
		else
		{
			SR_InHands[0].sprite = null;
		}
		ChangeCharacterAnimType(GetKindOfWeaponNumber());
	}

	private IEnumerator Motions()
	{
		LookAtThePlayer();
		if (freezingTime <= 0f)
		{
			AppearJump();
		}
		if (PlayerPrefs.GetInt("firstPlay") == 0 && TouchEvent.instance.CO_PlayerAI == null)
		{
			Generator.instance.SpawnObj(24, new Vector2(TF_CenterBone.position.x, TF_CenterBone.position.y), new float[0], TF_CenterBone);
			PlayerPrefs.SetInt("firstPlay", 1);
		}
		yield return new WaitForSeconds(2f);
		while (AllObjectsInfo.enemy[arrayNumForAllObjectsInfo].hp > 0f)
		{
			yield return new WaitForSeconds(0.1f);
			if (CheckAction())
			{
				continue;
			}
			if (freezingTime > 0f)
			{
				freezingTime -= 0.1f;
				continue;
			}
			LookAtThePlayer();
			if (PlayerInTheEnemyAttackZone(arrayNumForAllObjectsInfo) && Player.instance.hp > 0f && (SCRT_OnTheFloorSensor.onTheFloorFlag || tf.position.y > 3f) && Calc.IsVisibleCharacterOnScreen(tf.position))
			{
				kindOfMotion = 1;
				Attack();
			}
			else if (SCRT_OnTheFloorSensor.onTheFloorFlag)
			{
				if (SR_InHands[0].sprite != null && SR_InHands[0].sprite.name.Contains("Grenade") && Player.instance.hp > 0f && Calc.IsVisibleCharacterOnScreen(tf.position))
				{
					at.Play(throwing_NormalList[0]);
				}
				else if (Vector2.Distance(Player.instance.tf.position, AllObjectsInfo.enemy[arrayNumForAllObjectsInfo].pos) < Player.instance.hitSize + attackRange.x + 10f && Player.instance.tf.position.y > AllObjectsInfo.enemy[arrayNumForAllObjectsInfo].pos.y + 2f)
				{
					if (Random.Range(0, 5) == 0)
					{
						JumpToTheTarget();
					}
				}
				else if (at.GetCurrentAnimatorStateInfo(0).IsName("StickMan_Idle") && Player.instance.hp > 0f)
				{
					at.CrossFade(running_NormalList[0], 0.1f);
				}
			}
			else if (at.GetCurrentAnimatorStateInfo(0).IsName("StickMan_Idle"))
			{
				currentOnTheFloorFlag = false;
				if (!attackingNow)
				{
					at.Play(jumping_NormalList[0], -1, 0f);
				}
			}
		}
	}
}
